
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class FEATUser
	{
	
		
	
		#region Member Variables

		private int intUserID = int.MinValue;
		private string strUsername = string.Empty;
		private string strPassword = string.Empty;
		private string strFirstname = string.Empty;
		private string strLastname = string.Empty;
		private string strFullname = string.Empty;
		private bool bolGender;
		private DateTime dtmBirthdate = DateTime.MinValue;
		private string strBirthplace = string.Empty;
		private string strCurrentplace = string.Empty;
		private string strEmail = string.Empty;
		private string strPhone = string.Empty;
		private string strMobilephone = string.Empty;
		private string strCurrentCompany = string.Empty;
		private string strCurrentDepartment = string.Empty;
		private string strCurrentPosition = string.Empty;
		private DateTime dtmRegisterdate = DateTime.MinValue;
		private bool bolIsFEATMember;
		private DateTime dtmLastLogin = DateTime.MinValue;
		private string strProfilePicture = string.Empty;
		private string strUserIP = string.Empty;
		private DateTime dtmCreatedDate = DateTime.MinValue;
		private string strCreatedUser = string.Empty;
		private DateTime dtmUpdatedDate = DateTime.MinValue;
		private string strUpdatedUser = string.Empty;
		private bool bolIsDeleted;
		private DateTime dtmDeletedDate = DateTime.MinValue;
		private string strDeleteUser = string.Empty;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "FEATUser_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// UserID
		/// 
		/// </summary>
		public int UserID
		{
			get { return  intUserID; }
			set { intUserID = value; }
		}

		/// <summary>
		/// Username
		/// 
		/// </summary>
		public string Username
		{
			get { return  strUsername; }
			set { strUsername = value; }
		}

		/// <summary>
		/// Password
		/// 
		/// </summary>
		public string Password
		{
			get { return  strPassword; }
			set { strPassword = value; }
		}

		/// <summary>
		/// Firstname
		/// 
		/// </summary>
		public string Firstname
		{
			get { return  strFirstname; }
			set { strFirstname = value; }
		}

		/// <summary>
		/// Lastname
		/// 
		/// </summary>
		public string Lastname
		{
			get { return  strLastname; }
			set { strLastname = value; }
		}

		/// <summary>
		/// Fullname
		/// 
		/// </summary>
		public string Fullname
		{
			get { return  strFullname; }
			set { strFullname = value; }
		}

		/// <summary>
		/// Gender
		/// 
		/// </summary>
		public bool Gender
		{
			get { return  bolGender; }
			set { bolGender = value; }
		}

		/// <summary>
		/// Birthdate
		/// 
		/// </summary>
		public DateTime Birthdate
		{
			get { return  dtmBirthdate; }
			set { dtmBirthdate = value; }
		}

		/// <summary>
		/// Birthplace
		/// 
		/// </summary>
		public string Birthplace
		{
			get { return  strBirthplace; }
			set { strBirthplace = value; }
		}

		/// <summary>
		/// Currentplace
		/// 
		/// </summary>
		public string Currentplace
		{
			get { return  strCurrentplace; }
			set { strCurrentplace = value; }
		}

		/// <summary>
		/// Email
		/// 
		/// </summary>
		public string Email
		{
			get { return  strEmail; }
			set { strEmail = value; }
		}

		/// <summary>
		/// Phone
		/// 
		/// </summary>
		public string Phone
		{
			get { return  strPhone; }
			set { strPhone = value; }
		}

		/// <summary>
		/// Mobilephone
		/// 
		/// </summary>
		public string Mobilephone
		{
			get { return  strMobilephone; }
			set { strMobilephone = value; }
		}

		/// <summary>
		/// CurrentCompany
		/// 
		/// </summary>
		public string CurrentCompany
		{
			get { return  strCurrentCompany; }
			set { strCurrentCompany = value; }
		}

		/// <summary>
		/// CurrentDepartment
		/// 
		/// </summary>
		public string CurrentDepartment
		{
			get { return  strCurrentDepartment; }
			set { strCurrentDepartment = value; }
		}

		/// <summary>
		/// CurrentPosition
		/// 
		/// </summary>
		public string CurrentPosition
		{
			get { return  strCurrentPosition; }
			set { strCurrentPosition = value; }
		}

		/// <summary>
		/// Registerdate
		/// 
		/// </summary>
		public DateTime Registerdate
		{
			get { return  dtmRegisterdate; }
			set { dtmRegisterdate = value; }
		}

		/// <summary>
		/// IsFEATMember
		/// 
		/// </summary>
		public bool IsFEATMember
		{
			get { return  bolIsFEATMember; }
			set { bolIsFEATMember = value; }
		}

		/// <summary>
		/// LastLogin
		/// 
		/// </summary>
		public DateTime LastLogin
		{
			get { return  dtmLastLogin; }
			set { dtmLastLogin = value; }
		}

		/// <summary>
		/// ProfilePicture
		/// 
		/// </summary>
		public string ProfilePicture
		{
			get { return  strProfilePicture; }
			set { strProfilePicture = value; }
		}

		/// <summary>
		/// UserIP
		/// 
		/// </summary>
		public string UserIP
		{
			get { return  strUserIP; }
			set { strUserIP = value; }
		}

		/// <summary>
		/// CreatedDate
		/// 
		/// </summary>
		public DateTime CreatedDate
		{
			get { return  dtmCreatedDate; }
			set { dtmCreatedDate = value; }
		}

		/// <summary>
		/// CreatedUser
		/// 
		/// </summary>
		public string CreatedUser
		{
			get { return  strCreatedUser; }
			set { strCreatedUser = value; }
		}

		/// <summary>
		/// UpdatedDate
		/// 
		/// </summary>
		public DateTime UpdatedDate
		{
			get { return  dtmUpdatedDate; }
			set { dtmUpdatedDate = value; }
		}

		/// <summary>
		/// UpdatedUser
		/// 
		/// </summary>
		public string UpdatedUser
		{
			get { return  strUpdatedUser; }
			set { strUpdatedUser = value; }
		}

		/// <summary>
		/// IsDeleted
		/// 
		/// </summary>
		public bool IsDeleted
		{
			get { return  bolIsDeleted; }
			set { bolIsDeleted = value; }
		}

		/// <summary>
		/// DeletedDate
		/// 
		/// </summary>
		public DateTime DeletedDate
		{
			get { return  dtmDeletedDate; }
			set { dtmDeletedDate = value; }
		}

		/// <summary>
		/// DeleteUser
		/// 
		/// </summary>
		public string DeleteUser
		{
			get { return  strDeleteUser; }
			set { strDeleteUser = value; }
		}


		#endregion		
		
		
		#region Constructor

		public FEATUser()
		{
		}
		private static FEATUser _current;
		static FEATUser()
		{
			_current = new FEATUser();
		}
		public static FEATUser Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("FEAT_User_Select");
				objData.AddParameter("@Username", this.Username);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["UserID"]))	this.UserID = Convert.ToInt32(reader["UserID"]);
					if(!this.IsDBNull(reader["Username"]))	this.Username = Convert.ToString(reader["Username"]);
					if(!this.IsDBNull(reader["Password"]))	this.Password = Convert.ToString(reader["Password"]);
					if(!this.IsDBNull(reader["Firstname"]))	this.Firstname = Convert.ToString(reader["Firstname"]);
					if(!this.IsDBNull(reader["Lastname"]))	this.Lastname = Convert.ToString(reader["Lastname"]);
					if(!this.IsDBNull(reader["Fullname"]))	this.Fullname = Convert.ToString(reader["Fullname"]);
					if(!this.IsDBNull(reader["Gender"]))	this.Gender = Convert.ToBoolean(reader["Gender"]);
					if(!this.IsDBNull(reader["Birthdate"]))	this.Birthdate = Convert.ToDateTime(reader["Birthdate"]);
					if(!this.IsDBNull(reader["Birthplace"]))	this.Birthplace = Convert.ToString(reader["Birthplace"]);
					if(!this.IsDBNull(reader["Currentplace"]))	this.Currentplace = Convert.ToString(reader["Currentplace"]);
					if(!this.IsDBNull(reader["Email"]))	this.Email = Convert.ToString(reader["Email"]);
					if(!this.IsDBNull(reader["Phone"]))	this.Phone = Convert.ToString(reader["Phone"]);
					if(!this.IsDBNull(reader["Mobilephone"]))	this.Mobilephone = Convert.ToString(reader["Mobilephone"]);
					if(!this.IsDBNull(reader["CurrentCompany"]))	this.CurrentCompany = Convert.ToString(reader["CurrentCompany"]);
					if(!this.IsDBNull(reader["CurrentDepartment"]))	this.CurrentDepartment = Convert.ToString(reader["CurrentDepartment"]);
					if(!this.IsDBNull(reader["CurrentPosition"]))	this.CurrentPosition = Convert.ToString(reader["CurrentPosition"]);
					if(!this.IsDBNull(reader["Registerdate"]))	this.Registerdate = Convert.ToDateTime(reader["Registerdate"]);
					if(!this.IsDBNull(reader["IsFEATMember"]))	this.IsFEATMember = Convert.ToBoolean(reader["IsFEATMember"]);
					if(!this.IsDBNull(reader["LastLogin"]))	this.LastLogin = Convert.ToDateTime(reader["LastLogin"]);
					if(!this.IsDBNull(reader["ProfilePicture"]))	this.ProfilePicture = Convert.ToString(reader["ProfilePicture"]);
					if(!this.IsDBNull(reader["UserIP"]))	this.UserIP = Convert.ToString(reader["UserIP"]);
					if(!this.IsDBNull(reader["CreatedDate"]))	this.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
					if(!this.IsDBNull(reader["CreatedUser"]))	this.CreatedUser = Convert.ToString(reader["CreatedUser"]);
					if(!this.IsDBNull(reader["UpdatedDate"]))	this.UpdatedDate = Convert.ToDateTime(reader["UpdatedDate"]);
					if(!this.IsDBNull(reader["UpdatedUser"]))	this.UpdatedUser = Convert.ToString(reader["UpdatedUser"]);
					if(!this.IsDBNull(reader["IsDeleted"]))	this.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]);
					if(!this.IsDBNull(reader["DeletedDate"]))	this.DeletedDate = Convert.ToDateTime(reader["DeletedDate"]);
					if(!this.IsDBNull(reader["DeleteUser"]))	this.DeleteUser = Convert.ToString(reader["DeleteUser"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : FEAT_User
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("FEAT_User_Insert");
				if(this.UserID != int.MinValue) objData.AddParameter("@UserID", this.UserID);
				objData.AddParameter("@Username", this.Username);
				objData.AddParameter("@Password", this.Password);
				objData.AddParameter("@Firstname", this.Firstname);
				objData.AddParameter("@Lastname", this.Lastname);
				objData.AddParameter("@Fullname", this.Fullname);
				objData.AddParameter("@Gender", this.Gender);
				if(this.Birthdate != DateTime.MinValue) objData.AddParameter("@Birthdate", this.Birthdate);
				objData.AddParameter("@Birthplace", this.Birthplace);
				objData.AddParameter("@Currentplace", this.Currentplace);
				objData.AddParameter("@Email", this.Email);
				objData.AddParameter("@Phone", this.Phone);
				objData.AddParameter("@Mobilephone", this.Mobilephone);
				objData.AddParameter("@CurrentCompany", this.CurrentCompany);
				objData.AddParameter("@CurrentDepartment", this.CurrentDepartment);
				objData.AddParameter("@CurrentPosition", this.CurrentPosition);
				if(this.Registerdate != DateTime.MinValue) objData.AddParameter("@Registerdate", this.Registerdate);
				objData.AddParameter("@IsFEATMember", this.IsFEATMember);
				if(this.LastLogin != DateTime.MinValue) objData.AddParameter("@LastLogin", this.LastLogin);
				objData.AddParameter("@ProfilePicture", this.ProfilePicture);
				objData.AddParameter("@UserIP", this.UserIP);
				objData.AddParameter("@CreatedUser", this.CreatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : FEAT_User
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("FEAT_User_Update");
				if(this.UserID != int.MinValue)	objData.AddParameter("@UserID", this.UserID);
				else objData.AddParameter("@UserID", DBNull.Value);
				objData.AddParameter("@Username", this.Username);
				objData.AddParameter("@Password", this.Password);
				objData.AddParameter("@Firstname", this.Firstname);
				objData.AddParameter("@Lastname", this.Lastname);
				objData.AddParameter("@Fullname", this.Fullname);
				objData.AddParameter("@Gender", this.Gender);
				if(this.Birthdate != DateTime.MinValue)	objData.AddParameter("@Birthdate", this.Birthdate);
				else objData.AddParameter("@Birthdate", DBNull.Value);
				objData.AddParameter("@Birthplace", this.Birthplace);
				objData.AddParameter("@Currentplace", this.Currentplace);
				objData.AddParameter("@Email", this.Email);
				objData.AddParameter("@Phone", this.Phone);
				objData.AddParameter("@Mobilephone", this.Mobilephone);
				objData.AddParameter("@CurrentCompany", this.CurrentCompany);
				objData.AddParameter("@CurrentDepartment", this.CurrentDepartment);
				objData.AddParameter("@CurrentPosition", this.CurrentPosition);
				if(this.Registerdate != DateTime.MinValue)	objData.AddParameter("@Registerdate", this.Registerdate);
				else objData.AddParameter("@Registerdate", DBNull.Value);
				objData.AddParameter("@IsFEATMember", this.IsFEATMember);
				if(this.LastLogin != DateTime.MinValue)	objData.AddParameter("@LastLogin", this.LastLogin);
				else objData.AddParameter("@LastLogin", DBNull.Value);
				objData.AddParameter("@ProfilePicture", this.ProfilePicture);
				objData.AddParameter("@UserIP", this.UserIP);
				objData.AddParameter("@UpdatedUser", this.UpdatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : FEAT_User
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("FEAT_User_Delete");
				objData.AddParameter("@Username", this.Username);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : FEAT_User
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("FEAT_User_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	FEAT_User objFEAT_User = new FEAT_User();
			objFEATUser.UserID = txtUserID.Text;
			objFEATUser.Username = txtUsername.Text;
			objFEATUser.Password = txtPassword.Text;
			objFEATUser.Firstname = txtFirstname.Text;
			objFEATUser.Lastname = txtLastname.Text;
			objFEATUser.Fullname = txtFullname.Text;
			objFEATUser.Gender = txtGender.Text;
			objFEATUser.Birthdate = txtBirthdate.Text;
			objFEATUser.Birthplace = txtBirthplace.Text;
			objFEATUser.Currentplace = txtCurrentplace.Text;
			objFEATUser.Email = txtEmail.Text;
			objFEATUser.Phone = txtPhone.Text;
			objFEATUser.Mobilephone = txtMobilephone.Text;
			objFEATUser.CurrentCompany = txtCurrentCompany.Text;
			objFEATUser.CurrentDepartment = txtCurrentDepartment.Text;
			objFEATUser.CurrentPosition = txtCurrentPosition.Text;
			objFEATUser.Registerdate = txtRegisterdate.Text;
			objFEATUser.IsFEATMember = txtIsFEATMember.Text;
			objFEATUser.LastLogin = txtLastLogin.Text;
			objFEATUser.ProfilePicture = txtProfilePicture.Text;
			objFEATUser.UserIP = txtUserIP.Text;
			objFEATUser.CreatedDate = txtCreatedDate.Text;
			objFEATUser.CreatedUser = txtCreatedUser.Text;
			objFEATUser.UpdatedDate = txtUpdatedDate.Text;
			objFEATUser.UpdatedUser = txtUpdatedUser.Text;
			objFEATUser.IsDeleted = txtIsDeleted.Text;
			objFEATUser.DeletedDate = txtDeletedDate.Text;
			objFEATUser.DeleteUser = txtDeleteUser.Text;

		 
		 ******************************************************
		 
		 			txtUserID.Text = objFEATUser.UserID;
			txtUsername.Text = objFEATUser.Username;
			txtPassword.Text = objFEATUser.Password;
			txtFirstname.Text = objFEATUser.Firstname;
			txtLastname.Text = objFEATUser.Lastname;
			txtFullname.Text = objFEATUser.Fullname;
			txtGender.Text = objFEATUser.Gender;
			txtBirthdate.Text = objFEATUser.Birthdate;
			txtBirthplace.Text = objFEATUser.Birthplace;
			txtCurrentplace.Text = objFEATUser.Currentplace;
			txtEmail.Text = objFEATUser.Email;
			txtPhone.Text = objFEATUser.Phone;
			txtMobilephone.Text = objFEATUser.Mobilephone;
			txtCurrentCompany.Text = objFEATUser.CurrentCompany;
			txtCurrentDepartment.Text = objFEATUser.CurrentDepartment;
			txtCurrentPosition.Text = objFEATUser.CurrentPosition;
			txtRegisterdate.Text = objFEATUser.Registerdate;
			txtIsFEATMember.Text = objFEATUser.IsFEATMember;
			txtLastLogin.Text = objFEATUser.LastLogin;
			txtProfilePicture.Text = objFEATUser.ProfilePicture;
			txtUserIP.Text = objFEATUser.UserIP;
			txtCreatedDate.Text = objFEATUser.CreatedDate;
			txtCreatedUser.Text = objFEATUser.CreatedUser;
			txtUpdatedDate.Text = objFEATUser.UpdatedDate;
			txtUpdatedUser.Text = objFEATUser.UpdatedUser;
			txtIsDeleted.Text = objFEATUser.IsDeleted;
			txtDeletedDate.Text = objFEATUser.DeletedDate;
			txtDeleteUser.Text = objFEATUser.DeleteUser;

		 
		*******************************************************/
		
	}
}
